package com.homedo.odin.solution.jobhandler;

import com.homedo.odin.solution.service.AdServingServiceImpl;
import com.homedo.odin.solution.service.UserActionStatisServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时器 cron 表达式在线生成地址：http://www.cronmaker.com 注意这里只有6位，去掉最后一位即可
 *
 * @author chenlei
 * @date 2018/5/21
 */
@Component
public class Scheduler {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserActionStatisServiceImpl userActionStatisService;

    @Autowired
    private AdServingServiceImpl adServingService;


    /**
     * 统计前一天的用户行为日志数据
     */
    @Scheduled(cron = "0 1 0 1/1 * ?")
    public void genernateUserActionLogStatistics() {
        logger.info("用户行为日志统计定时器开始执行...");
        userActionStatisService.generateStatisticsOfYesterday();
        logger.info("用户行为日志统计定时器执行完毕...");
    }

    /**
     * 定时上下架当日需处理广告
     */
    @Scheduled(cron = "0 0 0 1/1 * ?")
    public void adServing() {
        logger.info("上下架当日需处理广告定时器开始执行...");
        adServingService.timingToAdvertise();
        adServingService.shelvesAdvertise();
        logger.info("上下架当日需处理广告定时器执行完毕...");
    }
}
